package com.pro.controller;

import com.pro.pojo.JsUser;
import com.pro.pojo.JsonData;
import com.pro.service.HomePageService;
import com.pro.utils.IpUtils;
import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.Request;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * @author 李佳豪
 * @date 2022/1/7 9:14
 */
@RestController
@RequestMapping("/HomePage")
public class HomePageController {
    @Autowired
    HomePageService homePageService;
    /**
     * @author 李佳豪
     */
    @RequestMapping(value = "/getAllUsersRegistrationTime")
    public JsonData getAllUsersRegistrationTime(){
        /*获取管理员今日、昨日、本月、总用户数量*/
        Map<String, Object> map = homePageService.getAllUsersRegistrationTime();
        return map!= null ?JsonData.buildSuccess(map):JsonData.buildError("服务器异常");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     *
     */
    @RequestMapping(value = "/getAllCreateDate")
    public JsonData getAllCreateDate(Integer courseStatus,Integer courseCstatus){
        Map<String, Object> map = homePageService.getAllCreateDate(courseStatus,courseCstatus);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     */
    @RequestMapping(value = "/getAllProductCreateDate")
    public JsonData getAllProductCreateDate(Integer productSate){
        Map<String, Object> map = homePageService.getAllProductCreateDate(productSate);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     */
    @RequestMapping(value = "/getAllUserCreateDate")
    public JsonData getAllUserCreateDate(){
        Map<String, Object> map = homePageService.getAllUserCreateDate();
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     */
    @RequestMapping(value = "/TotalOfThisWeekAndLastWeekCreateDate")
    public JsonData TotalOfThisWeekAndLastWeekCreateDate(Integer courseStatus,Integer courseCstatus){
        Map<String, Object> map = homePageService.TotalOfThisWeekAndLastWeekCreateDate(courseStatus,courseCstatus);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     */
    @RequestMapping(value = "/TotalOfThisWeekAndLastWeekProductCreateDate")
    public JsonData TotalOfThisWeekAndLastWeekProductCreateDate(Integer productSate){
        Map<String, Object> map = homePageService.TotalOfThisWeekAndLastWeekProductCreateDate(productSate);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     */
    @RequestMapping(value = "/TotalOfThisWeekAndLastWeekUserCreateDate")
    public JsonData TotalOfThisWeekAndLastWeekUserCreateDate(){
        Map<String, Object> map = homePageService.TotalOfThisWeekAndLastWeekUserCreateDate();
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.17 15:18
     * 修改用户头像及密码
     */
    @RequestMapping(value = "/UpdateUser")
    public JsonData UpdateUser(JsUser param) {
        boolean UpdateUser = homePageService.UpdateUser(param);
        return UpdateUser!=false?JsonData.buildSuccess(true):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.19 13:02
     * 获取mysql版本
     */
    @RequestMapping(value = "/getMysqlEdition")
    public JsonData getMysqlEdition() {
        String mysqlEdition = homePageService.getMysqlEdition();
        return mysqlEdition!=null?JsonData.buildSuccess(mysqlEdition):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.19 13:02
     * 获取本机信息
     */
    @RequestMapping(value = "/getNativeInformation")
    public JsonData getServer() {
        Map<String, Object> map = new HashMap<>();
        InetAddress inetAddress;//声明InetAddress对象
        try {
            inetAddress=InetAddress.getLocalHost();//实例化InetAddress对象，返回本地主机
            String hostName=inetAddress.getHostName();//获取本地主机名
            map.put("hostName",hostName);
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }

    /**
     * @author 李佳豪
     * @Date 2022.1.19 13:02
     * 获取mysql版本
     */
    @RequestMapping(value = "/getPort")
    public JsonData getPort(HttpServletRequest request) {
        //ip地址
        String serverIp = "";
        serverIp= IpUtils.getIp();

        int localPort = request.getLocalPort();
        Map<String, Object> map = new HashMap<>();
        map.put("serverIp",serverIp);
        map.put("localPort",localPort);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.19 13:02
     * 获取当前系统的信息
     */
    @RequestMapping(value = "/getWindows")
    public JsonData getWindows() {
        Map<String, Object> map = new HashMap<>();
        //当前系统名称
        String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.US);
//当前系统的位数X86?X64
        String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.US);
//获取当前系统的版本信息
        String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.US);
        map.put("OS_NAME",OS_NAME);
        map.put("OS_ARCH",OS_ARCH);
        map.put("OS_VERSION",OS_VERSION);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.19 13:02
     * 获取浏览器信息
     */
    @RequestMapping(value = "/getBrowserInformation")
    public JsonData getBrowserInformation(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
//获取浏览器信息
        Browser browser = UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getBrowser();
//获取浏览器版本号
        Version version = browser.getVersion(request.getHeader("User-Agent"));
        Map<String, Object> map = new HashMap<>();
        map.put("browser",browser.getName());
        map.put("version",version.getVersion());
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取上架商品数量
     */
    @RequestMapping(value = "/TotalAmountOfGoodsOnShelf")
    public JsonData TotalAmountOfGoodsOnShelf(Integer type, Integer result, Integer productSate)  {
        Integer integer = homePageService.TotalAmountOfGoodsOnShelf(type, result, productSate);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取上架课程数量
     */
    @RequestMapping(value = "/TotalVideoOverhead")
    public JsonData TotalVideoOverhead(Integer courseCstatus, Integer courseStatus)  {
        Integer integer = homePageService.TotalVideoOverhead(courseCstatus, courseStatus);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取发布微圈数量
     */
    @RequestMapping(value = "/TotalNumberOfPublishedMicrocircles")
    public JsonData TotalNumberOfPublishedMicrocircles(Integer details, Integer show){
        Integer integer = homePageService.TotalNumberOfPublishedMicrocircles( details, show);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取发布微圈数量
     */
    @RequestMapping(value = "/TotalNumberOfCompletedOrders")
    public JsonData TotalNumberOfCompletedOrders(Integer orderStatus) {
        Integer integer = homePageService.TotalNumberOfCompletedOrders(orderStatus);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取商品待审核数量
     */
    @RequestMapping(value = "/TotalProductStayExamine")
    public JsonData TotalProductStayExamine(Integer type, Integer result) {
        Integer integer = homePageService.TotalProductStayExamine(type,result);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取课程待审核数量
     */
    @RequestMapping(value = "/TotalCourseStayExamine")
    public JsonData TotalCourseStayExamine(Integer type, Integer result) {
        Integer integer = homePageService.TotalCourseStayExamine(type,result);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取微圈待审核数量
     */
    @RequestMapping(value = "/TotalMicroCircleStayExamine")
    public JsonData TotalMicroCircleStayExamine(Integer type, Integer result) {
        Integer integer = homePageService.TotalMicroCircleStayExamine(type,result);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.20 13:46
     * 获取退订待审核数量
     */
    @RequestMapping(value = "/TotalUnsubscribeStayExamine")
    public JsonData TotalUnsubscribeStayExamine(Integer orderStatus) {
        Integer integer = homePageService.TotalUnsubscribeStayExamine(orderStatus);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.22 13:29
     * 查看商品销量总数
     */
    @RequestMapping(value = "/getTotalProductSales")
    public JsonData getTotalProductSales(Integer orderType) {
        Integer integer = homePageService.getTotalProductSales(orderType);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.22 13:29
     * 查看商品收藏总数
     */
    @RequestMapping(value = "/getTotalVideoCollection")
    public JsonData getTotalVideoCollection(Integer collectionType){
        Integer integer = homePageService.getTotalVideoCollection(collectionType);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.22 13:29
     * 查看完成订单总数
     */
    @RequestMapping(value = "/getTotalNumberOfCompletedOrders")
    public JsonData getTotalNumberOfCompletedOrders(Integer orderType){
        Integer integer = homePageService.getTotalNumberOfCompletedOrders(orderType);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.22 13:29
     * 查看所有订单总数
     */
    @RequestMapping(value = "/getTotalOrders")
    public JsonData getTotalOrders(){
        Integer integer = homePageService.getTotalOrders();
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.22 13:29
     * 查看所有课程浏览总数
     */
    @RequestMapping(value = "/getCourseBrowseTotal")
    public JsonData getCourseBrowseTotal(){
        Integer integer = homePageService.getCourseBrowseTotal();
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.22 13:29
     * 查看所有课程点赞总数
     */
    @RequestMapping(value = "/getTotalVideoLikes")
    public JsonData getTotalVideoLikes(){
        Integer integer = homePageService.getTotalVideoLikes();
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.22 13:29
     * 查看微圈点赞总数
     */
    @RequestMapping(value = "/getMicroCircleFabulousCount")
    public JsonData getMicroCircleFabulousCount(Integer details,Integer show){
        Integer integer = homePageService.getMicroCircleFabulousCount(details,show);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.24 21:11
     * 查看前端用户数量
     */
    @RequestMapping(value = "/getTotalWebUser")
    public JsonData getTotalWebUser(Integer status){
        Integer integer = homePageService.getTotalWebUser(status);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.24 21:11
     * 查看后端用户数量
     */
    @RequestMapping(value = "/getTotalBackstageUser")
    public JsonData getTotalBackstageUser(Integer status){
        Integer integer = homePageService.getTotalBackstageUser(status);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.24 21:11
     * 查询创作者待审核数量
     */
    @RequestMapping(value = "/getCreatorExmaine")
    public JsonData getCreatorExmaine(Integer result){
        Integer integer = homePageService.getCreatorExmaine(result);
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.1.27 21:11
     * 查询进思用户数量
     */
    @RequestMapping(value = "/getTotalJinsiUser")
    public JsonData getTotalJinsiUser(){
        Integer integer = homePageService.getTotalJinsiUser();
        return integer!=null?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * @author 李佳豪
     * @Date 2022.2.6 11:11
     * 获取用户权限
     */
    @RequestMapping(value = "/getUserGrade")
    public JsonData getUserGrade(Integer userId){
        Integer userGrade = homePageService.getUserGrade(userId);
        return userGrade!=null?JsonData.buildSuccess(userGrade):JsonData.buildError("服务器错误");
    }

}
